package uml.behavioral.state.forum;

/**
 * 状态模式--具体状态类<br>
 * on 2023/1/6 14:32
 */
public class PrimaryState extends UserState {
    public PrimaryState(ForumUser user) {
        super(user);
    }

    public PrimaryState(UserState state) {
        super(state);
    }

    @Override
    public void commit(String msg) {
        System.out.println(user.getUserName() + "发表评论[初级]：" + msg);
        user.setIntegration(user.getIntegration() + commitForum);
        System.out.println("赚取积分:"+commitForum);
        stateSwitch();
    }

    @Override
    public void reply(String msg) {
        System.out.println(user.getUserName() + "回复评论[初级]：" + msg);
        user.setIntegration(user.getIntegration() + replyForum);
        System.out.println("赚取积分:"+replyForum);
        stateSwitch();
    }

    @Override
    public void fileDownload(String filName) {
        System.out.println(user.getUserName() + "下载文件[初级]：" + filName);
        System.out.println("抱歉，你积分不足以下载文件【最少100】，您的仅为" + user.getIntegration());
    }

    @Override
    protected void stateSwitch() {
        if (user.getIntegration() >= 100 && user.getIntegration() < 1000) {
            user.setState(new SeniorState(this));
        } else if (user.getIntegration() >= 1000) {
            user.setState(new ProfessionalState(this));
        } else {
            if (!user.isClosed()) {
                System.out.println("系统消息：您为论坛初级用户，积分不足，下载文件将受限，请发表品论、回复留言赚取积分！");
            }
        }
    }
}
